<template>
  <view :data-theme="g.theme">
    <BasicComponents></BasicComponents>
    <CustomNavbar title="买入卖出登记"></CustomNavbar>
    <ProForm
      ref="ProFormRef"
      :options="addForm.options"
      :editable="addForm.editable"
      @get-model="from => (addForm.form = from)"
      @save="saveMethod => (addForm.save = saveMethod)"
      @submit="submitForm"
    >
    </ProForm>

    <BottomButton @right-click="addForm.save"></BottomButton>
  </view>
</template>
<script setup lang="ts">
import { useForm } from "./hooks/use-addForm";
const { addForm, submitForm, getFindPositionsByUserId, getMoney, getAllUser } = useForm();
const g = useThemeStore();
onLoad(options => init(options));
const init = async options => {
  const { userId, quantity, dm } = options || {};
  await getAllUser();
  setSingleDictionaries(addForm, 1, "type");

  if (!userId) return;
  nextTick(() => {
    Object.assign(addForm.form, {
      type: 1,
      _dm: dm,
      userId: parseInt(userId),
      quantity,
      type2: "sell"
    });
    getFindPositionsByUserId();
    getMoney();
  });
};
</script>
